<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'home';
if($_SESSION['os']=='mobile'){
	cfc('core')->checklogin('jy_kefu/home/');
}
$return=array();
$params=array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1);
if($_RQ['p']){
	$_SESSION['kefu']['plugin']=$_RQ['p'];
	$_SESSION['kefu']['pid']=$_RQ['pid'];
}
if($_SESSION['kefu']['plugin'] && $_SESSION['kefu']['plugin']!='jy_kefu'){
	$params['plugin']=$_SESSION['kefu']['plugin'];
	$params['pid']=$_SESSION['kefu']['pid'];
}else{
	$params['plugin']='';
}
$return['list']=pdo_getall('jy_kefus',$params,'','','paixu desc');
$return['noreadnum']=pdo_count('jy_kefu_chatlog',array('uniacid'=>$_SESSION['uniacid'],'getmid'=>$_SESSION['uid'],'isread'=>0));
if($return['list']){
	foreach($return['list'] as &$item){
		$item['picurl']=$item['picurl']?tomedia($item['picurl']):'';
		if($item['type']==0){
			$item['linkurl']=custom_url('jy_kefu/chat//getmid='.$item['mid'],true);
		}elseif($item['type']==1){
			$item['linkurl']='http://wpa.qq.com/msgrd?v=3&uin='.$item['number'].'&site=qq&menu=yes';
		}elseif($item['type']==2){
			$item['linkurl']='tel:'.$item['number'];
		}elseif($item['type']==4 || $item['type']==5){
			$qrurl=pdo_get('core_qr',array('ticket'=>$item['qrticket']),'url');
			$item['linkurl']=$qrurl['url'];
		}elseif($item['type']==7){
			$item['linkurl']=custom_url('jy_kefu/chat//getmid='.$item['mid'],true);
		}elseif($item['type']==8){
			$item['worker']=json_decode($item['worker'],true);
			$item['linkurl']=$item['worker']['h5url'];
		}
		if($item['type']!=8){
			if(!$return['linkurl']){
				$return['linkurl']=$item['linkurl'];
				$return['type']=$item['type'];
				$return['kefumid']=$item['mid'];
			}
		}elseif($item['linkurl']){
			$return['linkurl']=$item['linkurl']?:$return['linkurl'];
			$return['type']=8;
		}
	}
}
$setting = pdo_get('jy_kefu_set',array('uniacid'=>$_SESSION['uniacid']));
$return['hdp'] = json_decode($setting['hdp'],true);
$return['sharedata']=array(
	'title'=>$setting['sharetitle'],
	'desc'=>$setting['sharedes'],
	'link'=>custom_url('jy_kefu/home//fromuser='.$_SESSION['uid'],true),
	'imgUrl'=>$setting['sharepicurl'] ? tomedia($setting['sharepicurl']) : '',
);
$settitle=$setting['title']?$setting['title']:'客服中心';
$return['url']=custom_url('/home/',true);
set_html('title',$settitle);
exi($return);